{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Main.LinReg"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ENV[\"COLUMNS\"]=92\n",
    "include(\"linreg.jl\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "LinReg is a simple linear regression example using artificially generated data. You can run the demo using `julia linreg.jl` on the command line or `julia> LinReg.main()` at the Julia prompt.  Use `julia linreg.jl --help` or `julia> LinReg.main(\"--help\")` for a list of options.  The quadratic loss will be printed at every epoch and optimized parameters will be returned.\n"
      ],
      "text/plain": [
       "  LinReg is a simple linear regression example using artificially generated data. You can\n",
       "  run the demo using \u001b[36mjulia linreg.jl\u001b[39m on the command line or \u001b[36mjulia> LinReg.main()\u001b[39m at the\n",
       "  Julia prompt. Use \u001b[36mjulia linreg.jl --help\u001b[39m or \u001b[36mjulia> LinReg.main(\"--help\")\u001b[39m for a list of\n",
       "  options. The quadratic loss will be printed at every epoch and optimized parameters will\n",
       "  be returned."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@doc LinReg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "usage: <PROGRAM> [--atype ATYPE] [--batchsize BATCHSIZE]\n",
      "                 [--epochs EPOCHS] [--epochsize EPOCHSIZE] [--fast]\n",
      "                 [--inputdims INPUTDIMS] [--lr LR] [--noise NOISE]\n",
      "                 [--outputdims OUTPUTDIMS] [--seed SEED]\n",
      "                 [--gcheck GCHECK]\n",
      "\n",
      "linreg.jl (c) Deniz Yuret, 2016. Linear regression example with\n",
      "artificial data.\n",
      "\n",
      "optional arguments:\n",
      "  --atype ATYPE         array type: Array for cpu, KnetArray for gpu\n",
      "                        (default: \"KnetArray\")\n",
      "  --batchsize BATCHSIZE\n",
      "                        number of instances in a minibatch (type:\n",
      "                        Int64, default: 20)\n",
      "  --epochs EPOCHS       number of epochs for training (type: Int64,\n",
      "                        default: 10)\n",
      "  --epochsize EPOCHSIZE\n",
      "                        number of instances per epoch (type: Int64,\n",
      "                        default: 10000)\n",
      "  --fast                skip loss printing for faster run\n",
      "  --inputdims INPUTDIMS\n",
      "                        input dimensions (type: Int64, default: 100)\n",
      "  --lr LR               learning rate (type: Float64, default: 0.02)\n",
      "  --noise NOISE         noise in data (type: Float64, default: 0.01)\n",
      "  --outputdims OUTPUTDIMS\n",
      "                        output dimensions (type: Int64, default: 10)\n",
      "  --seed SEED           random number seed: use a nonnegative int for\n",
      "                        repeatable results (type: Int64, default: -1)\n",
      "  --gcheck GCHECK       check N random gradients (type: Int64,\n",
      "                        default: 0)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "LinReg.main(\"--help\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "linreg.jl (c) Deniz Yuret, 2016. Linear regression example with artificial data.\n",
      "opts=(:atype, \"KnetArray\")(:fast, false)(:batchsize, 20)(:inputdims, 100)(:noise, 0.01)(:gcheck, 0)(:epochs, 10)(:epochsize, 10000)(:lr, 0.02)(:seed, -1)(:outputdims, 10)\n",
      "(:epoch, 0, :loss, 279.29912281017516)\n",
      "(:epoch, 1, :loss, 3.2841391102039124)\n",
      "(:epoch, 2, :loss, 0.12451598773851272)\n",
      "(:epoch, 3, :loss, 0.005496461591429495)\n",
      "(:epoch, 4, :loss, 0.001204591843233465)\n",
      "(:epoch, 5, :loss, 0.0010674375310083487)\n",
      "(:epoch, 6, :loss, 0.001057082944183507)\n",
      "(:epoch, 7, :loss, 0.0010421431332532701)\n",
      "(:epoch, 8, :loss, 0.0010556584157347718)\n",
      "(:epoch, 9, :loss, 0.0010718655257941196)\n",
      "(:epoch, 10, :loss, 0.0010454056583281217)\n",
      " 11.910316 seconds (4.31 M allocations: 388.958 MiB, 1.18% gc time)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "10×100 Knet.KnetArray{Float64,2}:\n",
       "  0.535962  -0.180765    0.502062   -0.830269   …  -0.336718    -0.451263  -0.73799 \n",
       " -0.15822    1.96376     0.0924558   1.20957       -0.0653471   -1.9417    -1.11417 \n",
       " -0.705148  -0.0368945   0.0107832  -0.896317      -0.0729226   -0.222262   0.621661\n",
       " -0.400268  -0.505988   -1.43152    -0.663949       0.515398    -0.777181   1.41011 \n",
       " -0.571489   1.09637     0.143749    0.0938551      0.437805     0.231478   1.01224 \n",
       " -1.01784   -2.3871     -1.30633    -0.559822   …  -0.760019     0.398349   0.733119\n",
       "  0.487045   0.335484   -1.5648      0.481123      -1.92221      1.60635   -0.550339\n",
       "  0.483115   0.693975   -0.654253   -1.10856       -1.30588      0.910409  -1.65094 \n",
       " -0.345085   1.84974     0.254797    1.25547        0.00807449  -1.48363   -0.03002 \n",
       " -0.452134  -1.68089     0.50553    -0.437732       1.65003      1.3965     0.42845 "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LinReg.main(\"\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.0.0",
   "language": "julia",
   "name": "julia-1.0"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.0.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
